package com.example.springbootdemo.controller;

import com.example.springbootdemo.model.Result;
import com.example.springbootdemo.model.UserModel;
import com.example.springbootdemo.server.UserServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@Slf4j
public class UserController {
    @Resource
    private UserServer userServer;

    @RequestMapping("/findAll")
    public Result findAll() {
        return userServer.findAll();
    }

    @RequestMapping("/findUserById/{id}")
    public Result findUserById(@PathVariable("id") String id) {
        return userServer.findUserById(id);
    }

    @PostMapping("/insertUser")
    public Result insertUser(@RequestBody UserModel userModel) {
        return userServer.insertUser(userModel);
    }

    @PostMapping("/updateUserById")
    public Result updateUserById(@RequestBody UserModel userModel) {
        return userServer.updateUserById(userModel);
    }

    @PostMapping("/deleteUserById/{id}")
    public Result deleteUserById(@PathVariable("id") String id) {
        return userServer.deleteUserById(id);
    }

    @PostMapping("/seachUser")
    public Result seachUser(@RequestBody UserModel userModel) {
        log.info("userModel:{}",userModel);
        return userServer.seachUser(userModel);
    }
}
